<?php
session_start();
if (isset($_POST['op'])){
    if(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"])=="xmlhttprequest"){
        $s=(int)addslashes(trim($_POST['s']));
        $openid=addslashes(trim($_POST['op']));
        include '../c/config.php';
        $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
        
        $mysqli->query("insert into ".$tableVer."_fen_log(openid,fen,createtime) values('".$openid."','".$s."','".date("Y-m-d H:i:s")."') ");
        $queryFen=$mysqli->query("select fen from ".$tableVer."_fen where openid='".$openid."' limit 0, 1");
        if($queryFen->num_rows>0){
            $getFenInfo=$queryFen->fetch_assoc();
            if ($getFenInfo['fen'] <  $s){
                $sql="update ".$tableVer."_fen set fen=".$s." where openid='".$openid."'";
                $query = $mysqli->query($sql);
                $mysqli->query("update zsu_phone_tong set fen=".$s." where openid='".$openid."' ");
                echo json_encode(array('s' =>'y'));
                exit;
            }
            echo json_encode(array('s' =>'l'));
            exit;
        }else{
            $mysqli->query("insert into ".$tableVer."_fen(openid,fen,createtime) values('".$openid."','".$s."','".date("Y-m-d H:i:s")."') ");
             $mysqli->query("update zsu_phone_tong set fen=".$s." where openid='".$openid."' ");
            echo json_encode(array('s' =>'y'));
            exit;
        }
        
        /**
        $queryG=$mysqli->query("select tid from ".$tableVer."_group where openid='".$_SESSION['openid']."' limit 0, 1");
        if($queryG->num_rows>0){
            $getG= $queryG->fetch_assoc();
            $tid=$getG['tid'];
            $queryGT=$mysqli->query("select openid from ".$tableVer."_group where tid='".$tid."' limit 0, 3");
            $zongFen=0;
            while ($list=$queryGT->fetch_assoc()){
                $queryFen=$mysqli->query("select fen from ".$tableVer."_fen where openid='".$list['openid']."' limit 0, 1");
                if($queryFen->num_rows>0){
                    $getFen=$queryFen->fetch_assoc();
                    $zongFen=$zongFen+$getFen['fen'];
                }
            }
            $query = $mysqli->query("update ".$tableVer."_team set fen=".$zongFen." where id='".$tid."'"); 
        }
        */

    }
    echo json_encode(array('s' =>'l'));
}
?>